package edu.uoc.tdp.client.proves;

import edu.uoc.tdp.beans.proves.EstatProva;
import edu.uoc.tdp.beans.proves.Prova;
import edu.uoc.tdp.common.EOlympicsException;
import edu.uoc.tdp.common.EOlympicsUtils;
import edu.uoc.tdp.common.RemotProvesInterface;
import edu.uoc.tdp.common.TDSLanguageUtils;

import java.awt.Font;
import java.awt.event.WindowEvent;
import java.net.MalformedURLException;

import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.text.ParseException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import javax.swing.text.MaskFormatter;

public class PanelMantenimentGestioProves extends JFrame {
    private JButton jBBuscarProva;private JButton jBCancelarProva;  private JButton jBSortir;
    private JButton jBCrearProva2;private JButton jBGuardarProva;private JLabel jLDataAlta;
    private JButton jBCrearProva;
  
    private JLabel jLDataBaixa;  private JLabel jLDataModificacio;private JLabel jLDescripcio;  
    private JLabel jLEsborradaE;private JLabel jLEsborradaF;private JLabel jLEstat;
    private JLabel jLEstatLabel;private JLabel jLFinsE;private JLabel jLFinsF; private JLabel jLInscripcio;
    private JLabel jLInscripcioDe;private JLabel jLInscripcioFins;private JLabel jLModificadaE;
    private JLabel jLModificadaF;private JLabel jLNPreguntesE;private JLabel jLNPreguntesF;    
    private JLabel jLNombrePlaces;private JLabel jLRealitzacioE;private JLabel jLRealitzacioF;    
    private JLabel jLdeE;private JLabel jLdeEF;

    private JPanel jPButtons;private JPanel jPanelProva;private JPanel jPanelEliminatoria;private JPanel jPanelFinal;    
    
    private JScrollPane jScrollPaneE;private JScrollPane jScrollPaneF;
    
    private JTextField jTDescripcio;private JTextField jTFiInscripcio;private JTextField jTIniInscripcio;    
    private JTextField jTIniRealitzacioE;private JTextField jTIniRealitzacioF;
    private JTextField jTFiRealitzacioE;private JTextField jTFiRealitzacioF;
    
    private JLabel jTEsborradaE;private JLabel jTEsborradaF;
    private JLabel jTModificadaE;private JLabel jTModificadaF;
    private JLabel jTextDataAlta;private JLabel jTextDataBaixa;private JLabel jTextDataModificacio;
    
    private JComboBox jTNombrePlaces;private JComboBox jTNPreguntesE;private JComboBox jTNPreguntesF;
    
    private JTable jTableE;private JTable jTableF;
    
    private Font fontEtiqueta;private Font fontText;private Font fontTaula;private Font fontCapa;
    private final int ampleCombo=60;private final int altCombo=20;
    private final int ampleBoto=15; private final int altBoto=15;
    
    private RemotProvesInterface remotProves;
    private Prova prova;
    private String url="rmi://localhost/RemotProvesImpl";
    public PanelMantenimentGestioProves() throws ParseException{
        this.setBounds(50, 100, 600, 700);
        fontEtiqueta=new Font("Tahoma", 0, 12);
        fontText=new Font("Tahoma", 0, 12);
        fontTaula=new Font("Tahoma", 0, 12);
        fontCapa=new Font("Tahoma", 0, 15);
        initComponents();
        borrarDades();
       
        setPanellBotons();        
        setPanellProva();
        setFinestra();
        
        pintarEtiquetes();
        
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {            
            public void windowClosing(java.awt.event.WindowEvent evt) {
                tancarFinestra(evt);
            }
        });
        
    }
    public PanelMantenimentGestioProves(Prova prova, RemotProvesInterface remotProves) throws ParseException {        
        this();
        this.prova=prova;
        this.remotProves=remotProves;
        carregarProva();
        pack();
    }    
    private void initComponents() throws ParseException {                       
        jPButtons = new JPanel();
        jBCrearProva = new JButton();
        jBCancelarProva = new JButton();
        jBCrearProva2 = new JButton();
        jBGuardarProva = new JButton();
        jBBuscarProva = new JButton();
        jBSortir = new JButton();
        jPanelProva = new JPanel();
        jLDescripcio = new JLabel();
        jTDescripcio = new JTextField();
        jLNombrePlaces = new JLabel();
        jTNombrePlaces = new JComboBox();
        jLEstatLabel = new JLabel();
        jLEstat = new JLabel();
        jLInscripcio = new JLabel();
        jLInscripcioDe = new JLabel();
        jTIniInscripcio = new JFormattedTextField(new MaskFormatter("##/##/####"));  
        jLInscripcioFins = new JLabel();
        jTFiInscripcio = new JFormattedTextField(new MaskFormatter("##/##/####"));  
        jTextDataAlta = new JLabel();
        jLDataAlta = new JLabel();
        jLDataModificacio = new JLabel();
        jTextDataModificacio = new JLabel();
        jLDataBaixa = new JLabel();
        jTextDataBaixa = new JLabel();
        jPanelEliminatoria = new JPanel();
        jLNPreguntesE = new JLabel();
        jTNPreguntesE = new JComboBox();  
        jLRealitzacioE = new JLabel();
        jTIniRealitzacioE = new JFormattedTextField(new MaskFormatter("##/##/####"));  
        jTFiRealitzacioE = new JFormattedTextField(new MaskFormatter("##/##/####"));  
        jLFinsE = new JLabel();
        jLdeE = new JLabel();
        jLModificadaE = new JLabel();
        jTModificadaE = new JLabel();
        jTEsborradaE = new JLabel();
        jLEsborradaE = new JLabel();
        jScrollPaneE = new JScrollPane();
        jTableE = null;
        jPanelFinal = new JPanel();
        jLNPreguntesF = new JLabel();
        jTNPreguntesF = new JComboBox();  
        jLRealitzacioF = new JLabel();
        jTIniRealitzacioF = new JFormattedTextField(new MaskFormatter("##/##/####"));  
        jTFiRealitzacioF = new JFormattedTextField(new MaskFormatter("##/##/####"));  
        jLFinsF = new JLabel();
        jLdeEF = new JLabel();
        jLModificadaF = new JLabel();
        jTModificadaF = new JLabel();
        jTEsborradaF = new JLabel();
        jLEsborradaF = new JLabel();
        jScrollPaneF = new JScrollPane();
        jTableF = null;
       
        jLDescripcio.setFont(fontEtiqueta);jLDescripcio.setHorizontalAlignment(SwingConstants.RIGHT);                
        jTDescripcio.setFont(fontText);jTDescripcio.setHorizontalAlignment(SwingConstants.LEFT);        
        jLNombrePlaces.setFont(fontEtiqueta);jLNombrePlaces.setHorizontalAlignment(SwingConstants.RIGHT);        
        jTNombrePlaces.setFont(fontText); 
        jLEstatLabel.setFont(fontEtiqueta); jLEstatLabel.setHorizontalAlignment(SwingConstants.RIGHT);        
        jLEstat.setFont(fontCapa);jLEstat.setHorizontalAlignment(SwingConstants.CENTER); jLEstat.setForeground(java.awt.SystemColor.activeCaption);        
        jLInscripcio.setFont(fontEtiqueta);jLInscripcio.setHorizontalAlignment(SwingConstants.RIGHT);        
        jLInscripcioDe.setFont(fontEtiqueta); jLInscripcioDe.setHorizontalAlignment(SwingConstants.RIGHT);        
        jTIniInscripcio.setFont(fontEtiqueta);jTIniInscripcio.setHorizontalAlignment(JTextField.CENTER);
        jLInscripcioFins.setFont(fontEtiqueta); jLInscripcioFins.setHorizontalAlignment(SwingConstants.RIGHT);        
        jTFiInscripcio.setFont(fontText); jTFiInscripcio.setHorizontalAlignment(JTextField.CENTER);        
        jTextDataAlta.setFont(fontText); jTextDataAlta.setHorizontalAlignment(JTextField.CENTER);        
        jLDataAlta.setFont(fontEtiqueta);jLDataAlta.setHorizontalAlignment(SwingConstants.RIGHT);        
        jLDataModificacio.setFont(fontEtiqueta);jLDataModificacio.setHorizontalAlignment(SwingConstants.RIGHT);        
        jTextDataModificacio.setFont(fontText);jTextDataModificacio.setHorizontalAlignment(JTextField.CENTER);        
        jLDataBaixa.setFont(fontEtiqueta);jLDataBaixa.setHorizontalAlignment(SwingConstants.RIGHT);        
        jTextDataBaixa.setFont(fontText);jTextDataBaixa.setHorizontalAlignment(JTextField.CENTER);  
        //eliminatoria        
        jLNPreguntesE.setFont(fontEtiqueta);jLNPreguntesE.setHorizontalAlignment(SwingConstants.RIGHT);        
        jTNPreguntesE.setFont(fontText);                
        jLRealitzacioE.setFont(fontEtiqueta);jLRealitzacioE.setHorizontalAlignment(SwingConstants.RIGHT);        
        jTIniRealitzacioE.setFont(fontText);jTIniRealitzacioE.setHorizontalAlignment(JTextField.CENTER);
        jTFiRealitzacioE.setFont(fontText); jTFiRealitzacioE.setHorizontalAlignment(JTextField.CENTER);
        jLFinsE.setFont(fontEtiqueta);jLFinsE.setHorizontalAlignment(SwingConstants.RIGHT);
        jLdeE.setFont(fontEtiqueta);jLdeE.setHorizontalAlignment(SwingConstants.RIGHT);
        jLModificadaE.setFont(fontEtiqueta);jLModificadaE.setHorizontalAlignment(SwingConstants.RIGHT);
        jTModificadaE.setFont(fontText);jTModificadaE.setHorizontalAlignment(JTextField.CENTER);
        jTEsborradaE.setFont(fontText);jTEsborradaE.setHorizontalAlignment(JTextField.CENTER);        
        jLEsborradaE.setFont(fontEtiqueta);jLEsborradaE.setHorizontalAlignment(SwingConstants.RIGHT); 
        //final
        jLNPreguntesF.setFont(fontEtiqueta); jLNPreguntesF.setHorizontalAlignment(SwingConstants.RIGHT);
        jTNPreguntesF.setFont(fontText);         
        jLRealitzacioF.setFont(fontEtiqueta);jLRealitzacioF.setHorizontalAlignment(SwingConstants.RIGHT);
        jTIniRealitzacioF.setFont(fontText);jTIniRealitzacioF.setHorizontalAlignment(JTextField.CENTER);
        jTFiRealitzacioF.setFont(fontText);jTFiRealitzacioF.setHorizontalAlignment(JTextField.CENTER);
        jLFinsF.setFont(fontEtiqueta);jLFinsF.setHorizontalAlignment(SwingConstants.RIGHT);
        jLdeEF.setFont(fontEtiqueta);jLdeEF.setHorizontalAlignment(SwingConstants.RIGHT);
        jLModificadaF.setFont(fontEtiqueta);jLModificadaF.setHorizontalAlignment(SwingConstants.RIGHT);
        jTModificadaF.setFont(fontText);jTModificadaF.setHorizontalAlignment(JTextField.CENTER);
        jTEsborradaF.setFont(fontText);jTEsborradaF.setHorizontalAlignment(JTextField.CENTER);
        jLEsborradaF.setFont(fontEtiqueta);jLEsborradaF.setHorizontalAlignment(SwingConstants.RIGHT);
        
        //listenets
        jTNPreguntesE.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTNPreguntesEChange(evt);
            }
        });
        jTNPreguntesF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTNPreguntesFChange(evt);
            }
        });
        
         jBBuscarProva.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                try {
                    try {
                        ActionBuscarProva(evt);
                    } catch (EOlympicsException ex) {
                        Logger.getLogger(PanelMantenimentGestioProves.class.getName()).log(Level.SEVERE, null, ex);
                    }
                } catch (NotBoundException ex) {
                    Logger.getLogger(PanelMantenimentGestioProves.class.getName()).log(Level.SEVERE, null, ex);
                } catch (MalformedURLException ex) {
                    Logger.getLogger(PanelMantenimentGestioProves.class.getName()).log(Level.SEVERE, null, ex);
                } catch (RemoteException ex) {
                    Logger.getLogger(PanelMantenimentGestioProves.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
         
        jBCancelarProva.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ActionCancelarProva(evt);
            }
        }); 
        jBSortir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tancarFinestra1(evt);
            }
        }); 
        jBCrearProva.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ActionCrearProva(evt);
            }
        }); 
        jBCrearProva2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ActionCrearProva2(evt);
            }
        });
         jBGuardarProva.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ActionGuardarProva(evt);
            }
        });        
         
    }
    private modelDadesPreguntaResposta carregarTaula(Integer nPreguntes){
        String [] columnes={"Pregunta","A","B","C","D"};        
          Object[][] dades=new Object[nPreguntes][5];                          
        modelDadesPreguntaResposta dadesTaula;
          for(int i=0;i<nPreguntes;i++){
            ButtonGroup bG=new ButtonGroup();
            for(int j=0; j<5;j++){
                if(j==0){
                    dades[i][j]=i+1+"";    
                }
                else{                    
                    dades[i][j]=new Boolean(false);                   
                }                
            }                        
        }        
        dadesTaula=new modelDadesPreguntaResposta(columnes,dades,EstatProva.INICIAL);
        return dadesTaula;        
    }    
    private void jTNPreguntesEChange(java.awt.event.ActionEvent evt) {
        if(jTNPreguntesE.getSelectedIndex()>=0){           
                jTableE=null;
                jTableE= new JTable(carregarTaula(Integer.parseInt(jTNPreguntesE.getSelectedItem().toString())));                
                jScrollPaneE.setViewportView(jTableE);
                        
        }
        
    }    
    private void jTNPreguntesFChange(java.awt.event.ActionEvent evt) {
        if(jTNPreguntesF.getSelectedIndex()>=0){
            jTableF=null;
            jTableF= new JTable(carregarTaula(Integer.parseInt(jTNPreguntesF.getSelectedItem().toString())));        
            jScrollPaneF.setViewportView(jTableF);
        }
    }
    private void ActionBuscarProva(java.awt.event.ActionEvent evt) throws NotBoundException, MalformedURLException, RemoteException, EOlympicsException {
        
        
    }
    private void ActionCancelarProva(java.awt.event.ActionEvent evt) {
        
    }
    private void tancarFinestra1(java.awt.event.ActionEvent evt) {
        dispose();
        System.exit(0);
    }
    private void ActionCrearProva(java.awt.event.ActionEvent evt) {
        
    }      
    private void ActionCrearProva2(java.awt.event.ActionEvent evt) {
        
    }   
    private void ActionGuardarProva(java.awt.event.ActionEvent evt) {
        
    }    
                 
    private void setPanellRonda(JPanel panel, JScrollPane jScroll, JLabel jLNPreguntes,
                                       JComboBox jTNPreguntes,JLabel jLEsborrada, JLabel jLModificada,
                                       JLabel jLRealitzacio, JLabel jLde, JTextField jTIniRealitzacio,
                                       JLabel jLFins, JTextField jTFiRealitzacio, JLabel jTModificada,
                                       JLabel jTEsborrada) throws ParseException{       
      javax.swing.GroupLayout jPanelEliminatoriaLayout = new javax.swing.GroupLayout(panel);
        panel.setLayout(jPanelEliminatoriaLayout);
        jPanelEliminatoriaLayout.setHorizontalGroup(
            jPanelEliminatoriaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
           .addGroup(jPanelEliminatoriaLayout.createSequentialGroup()
            .addGap(7, 7, 7)
                .addComponent(jScroll, javax.swing.GroupLayout.PREFERRED_SIZE,330, javax.swing.GroupLayout.PREFERRED_SIZE)
               .addContainerGap(10,Short.MAX_VALUE)) 
                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanelEliminatoriaLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanelEliminatoriaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelEliminatoriaLayout.createSequentialGroup()
                        .addComponent(jLNPreguntes)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTNPreguntes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanelEliminatoriaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLEsborrada, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLModificada, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            
                    .addGroup(jPanelEliminatoriaLayout.createSequentialGroup()
                        
                        .addComponent(jLRealitzacio, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLde, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(4, 4, 4)
                        .addComponent(jTIniRealitzacio, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                       // .addGap(4, 4, 4)
                        .addComponent(jLFins, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(4, 4, 4)
                        .addComponent(jTFiRealitzacio, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelEliminatoriaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    //.addComponent(jTFiRealitzacioE, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTModificada, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                    .addComponent(jTEsborrada, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );
        jPanelEliminatoriaLayout.setVerticalGroup(
            jPanelEliminatoriaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelEliminatoriaLayout.createSequentialGroup()
                .addGroup(jPanelEliminatoriaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)                
                    .addGroup(jPanelEliminatoriaLayout.createSequentialGroup()
                        .addGroup(jPanelEliminatoriaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLNPreguntes)
                            .addComponent(jTNPreguntes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLModificada))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLEsborrada))
                
                    .addGroup(jPanelEliminatoriaLayout.createSequentialGroup()
                        .addComponent(jTModificada, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTEsborrada, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(30, 30, 30)
                        .addGroup(jPanelEliminatoriaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            
                            .addComponent(jTFiRealitzacio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLFins)
                            .addComponent(jTIniRealitzacio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLde)
                            
                            .addComponent(jLRealitzacio))))
                .addGap(18, 18, 18)
                .addComponent(jScroll, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE))
        );
      
    } 
    
    
    
    private void setPanellBotons(){
        GroupLayout jPButtonsLayout = new GroupLayout(jPButtons);
        jPButtons.setLayout(jPButtonsLayout);
        jPButtonsLayout.setHorizontalGroup(
            jPButtonsLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(jPButtonsLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jBCrearProva, GroupLayout.DEFAULT_SIZE, ampleBoto, Short.MAX_VALUE)
                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBCrearProva2, GroupLayout.DEFAULT_SIZE, ampleBoto, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(jBCancelarProva, GroupLayout.DEFAULT_SIZE, ampleBoto, Short.MAX_VALUE)
                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBGuardarProva, GroupLayout.DEFAULT_SIZE, ampleBoto, Short.MAX_VALUE)
                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBBuscarProva, GroupLayout.DEFAULT_SIZE, ampleBoto, Short.MAX_VALUE)
                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBSortir, GroupLayout.DEFAULT_SIZE, ampleBoto, Short.MAX_VALUE)
                
                 .addComponent(jLEstatLabel, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE)
                 .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                 .addComponent(jLEstat, GroupLayout.PREFERRED_SIZE, 80, GroupLayout.PREFERRED_SIZE)
                
                
                
                .addGap(367, 367, 367))
        );
        jPButtonsLayout.setVerticalGroup(
            jPButtonsLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(jPButtonsLayout.createSequentialGroup()
                .addGroup(jPButtonsLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(jBCrearProva, GroupLayout.DEFAULT_SIZE, altBoto, Short.MAX_VALUE)
                    .addComponent(jBCrearProva2, GroupLayout.DEFAULT_SIZE, altBoto, Short.MAX_VALUE)
                    .addComponent(jBCancelarProva, GroupLayout.DEFAULT_SIZE, altBoto, Short.MAX_VALUE)
                    .addComponent(jBGuardarProva, GroupLayout.DEFAULT_SIZE, altBoto, Short.MAX_VALUE)
                    .addComponent(jBBuscarProva, GroupLayout.DEFAULT_SIZE, altBoto, Short.MAX_VALUE)
                    .addComponent(jBSortir, GroupLayout.DEFAULT_SIZE, altBoto, Short.MAX_VALUE)
                    .addComponent(jLEstat,GroupLayout.DEFAULT_SIZE, altBoto, Short.MAX_VALUE)
                    .addComponent(jLEstatLabel,GroupLayout.DEFAULT_SIZE, altBoto, Short.MAX_VALUE))
                .addContainerGap())
        );

    }
    private void setPanellProva(){
        GroupLayout jPanelProvaLayout = new GroupLayout(jPanelProva);
        jPanelProva.setLayout(jPanelProvaLayout);
        
        //horitzontal panelProva
        jPanelProvaLayout.setHorizontalGroup(
            jPanelProvaLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(jPanelProvaLayout.createSequentialGroup()
                .addGroup(jPanelProvaLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelProvaLayout.createSequentialGroup()
                        .addComponent(jLDescripcio, GroupLayout.PREFERRED_SIZE, 80, GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTDescripcio, GroupLayout.PREFERRED_SIZE, 393, GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLNombrePlaces, GroupLayout.PREFERRED_SIZE, 80, GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTNombrePlaces, GroupLayout.PREFERRED_SIZE,ampleCombo, GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED))
                        //.addComponent(jLEstatLabel, GroupLayout.PREFERRED_SIZE, 80, GroupLayout.PREFERRED_SIZE)
                        //.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        //.addComponent(jLEstat, GroupLayout.PREFERRED_SIZE, 149, GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanelProvaLayout.createSequentialGroup()
                        .addGroup(jPanelProvaLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addGroup(jPanelProvaLayout.createSequentialGroup()
                                .addGap(1, 1, 1)
                                .addComponent(jLInscripcio, GroupLayout.PREFERRED_SIZE, 114, GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanelProvaLayout.createSequentialGroup()
                                .addGap(16, 16, 16)
                                .addComponent(jLDataAlta, GroupLayout.PREFERRED_SIZE, 68, GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextDataAlta, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanelProvaLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addGroup(jPanelProvaLayout.createSequentialGroup()
                                .addComponent(jLDataModificacio, GroupLayout.PREFERRED_SIZE, 124, GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextDataModificacio, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE)
                                .addGap(1, 1, 1)
                                .addComponent(jLDataBaixa, GroupLayout.PREFERRED_SIZE, 124, GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextDataBaixa, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanelProvaLayout.createSequentialGroup()
                                .addComponent(jLInscripcioDe, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTIniInscripcio, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE)
                                .addGap(1, 1, 1)
                                .addComponent(jLInscripcioFins, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTFiInscripcio, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        //vertical panelProva
        jPanelProvaLayout.setVerticalGroup(
            jPanelProvaLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(jPanelProvaLayout.createSequentialGroup()
                .addGroup(jPanelProvaLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(jLDescripcio)
                    .addComponent(jTDescripcio, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLNombrePlaces)
                    .addComponent(jTNombrePlaces, GroupLayout.PREFERRED_SIZE, altCombo, GroupLayout.PREFERRED_SIZE))
                    //.addComponent(jLEstat)
                    //.addComponent(jLEstatLabel))
                .addGap(11, 11, 11)
                .addGroup(jPanelProvaLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(jLInscripcio)
                    .addComponent(jLInscripcioDe)
                    .addComponent(jTIniInscripcio, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLInscripcioFins)
                    .addComponent(jTFiInscripcio, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelProvaLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextDataAlta, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextDataBaixa, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLDataAlta)
                    .addComponent(jLDataBaixa)
                    .addComponent(jTextDataModificacio, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLDataModificacio)))
        );

    }
    private void setFinestra(){
        GroupLayout layout = new GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                     .addComponent(jPButtons, GroupLayout.PREFERRED_SIZE, 300, Short.MAX_VALUE)//800
                    //.addComponent(jPButtons, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanelProva, 0, 700, Short.MAX_VALUE))//800
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanelEliminatoria, GroupLayout.PREFERRED_SIZE, 350, GroupLayout.PREFERRED_SIZE)
                        //.addComponent(jPanelEliminatoria, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanelFinal, GroupLayout.PREFERRED_SIZE, 350, GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
                
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPButtons, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelProva, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanelEliminatoria, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanelFinal, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        
        
    }
    private void tancarFinestra(WindowEvent evt){
          dispose();
          System.exit(0);
      }
    private void borrarDades(){
         jPanelProva.setBorder(BorderFactory.createTitledBorder(null,TDSLanguageUtils.getMessage("proves.pantalla.manteniment.titoltext.jPanelProva1"),
                                             TitledBorder.DEFAULT_JUSTIFICATION,TitledBorder.DEFAULT_POSITION, fontCapa));                                     
         jTDescripcio.setText(""); 
         jTFiInscripcio.setText(""); 
         jTIniInscripcio.setText("");    
         jTIniRealitzacioE.setText(""); 
         jTIniRealitzacioF.setText("");
         jTFiRealitzacioE.setText(""); 
         jTFiRealitzacioF.setText("");    
         jTEsborradaE.setText(""); 
         jTEsborradaF.setText("");
         jTModificadaE.setText(""); 
         jTModificadaF.setText("");
         jTextDataAlta.setText(""); 
         jTextDataBaixa.setText(""); 
         jTextDataModificacio.setText("");
         jTNombrePlaces.setSelectedIndex(-1);
         //estic qui CAL ANAR PER FEINA QUE N'ESTIC FINS COLLONS
         //jTNombrePlaces.s
         
         jTNPreguntesE.setSelectedIndex(-1);
         jTNPreguntesF.setSelectedIndex(-1);
    }
    private void habilitarControls(boolean editable){
         jTDescripcio.setEditable(editable);
         jTFiInscripcio.setEditable(editable); 
         jTIniInscripcio.setEditable(editable);    
         jTIniRealitzacioE.setEditable(editable); 
         jTIniRealitzacioF.setEditable(editable);
         jTFiRealitzacioE.setEditable(editable); 
         jTFiRealitzacioF.setEditable(editable);             
         jTNombrePlaces.setEditable(editable); 
         jTNPreguntesE.setEditable(editable); 
         jTNPreguntesF.setEditable(editable);
    }
    private void carregarProva() throws ParseException{
         jPanelProva.setBorder(BorderFactory.createTitledBorder(null,TDSLanguageUtils.getMessage("proves.pantalla.manteniment.titoltext.jPanelProva")+": " +prova.getIdProva(),
                                             TitledBorder.DEFAULT_JUSTIFICATION,TitledBorder.DEFAULT_POSITION, fontCapa));                                     
                       
         if(prova.getRondaEliminatoria()!=null){
             setPanellRonda(jPanelEliminatoria,jScrollPaneE,jLNPreguntesE,jTNPreguntesE,jLEsborradaE, jLModificadaE,jLRealitzacioE, jLdeE, jTIniRealitzacioE,jLFinsE, jTFiRealitzacioE, jTModificadaE,jTEsborradaE);
             jTIniRealitzacioE.setText(EOlympicsUtils.getStringDate(prova.getRondaEliminatoria().getDataIniRealitzacio())); 
             jTFiRealitzacioE.setText(EOlympicsUtils.getStringDate(prova.getRondaEliminatoria().getDataFiRealitzacio())); 
             jTNPreguntesE.setModel(carregarCombo(3,30));jTNPreguntesE.setSelectedItem(2); 
             jTNPreguntesE.setSelectedItem(prova.getRondaEliminatoria().getNombrePreguntes());
         }
         else{
             jPanelEliminatoria.setVisible(false);
         }
         if(prova.getRondaFinal()!=null){
             setPanellRonda(jPanelFinal,jScrollPaneF,jLNPreguntesF,jTNPreguntesF,jLEsborradaF, jLModificadaF,jLRealitzacioF, jLdeEF, jTIniRealitzacioF,jLFinsF, jTFiRealitzacioF, jTModificadaF,jTEsborradaF);
             jTFiRealitzacioF.setText(EOlympicsUtils.getStringDate(prova.getRondaFinal().getDataFiRealitzacio()));    
             jTIniRealitzacioF.setText(EOlympicsUtils.getStringDate(prova.getRondaFinal().getDataIniRealitzacio()));
             jTNPreguntesF.setModel(carregarCombo(3,30));jTNPreguntesF.setSelectedItem(2); 
             jTNPreguntesF.setSelectedItem(prova.getRondaFinal().getNombrePreguntes());
         
         }
         else{
             jPanelFinal.setVisible(false);
         }
             
        
        
        //setPanellEliminatoria(jPanelEliminatoria);        
        //setPanellEliminatoria(jPanelFinal);        
        //setPanellFinal();
         jTDescripcio.setText(prova.getDescripcio()); 
         //jTFiInscripcio.setText("01/05/2012"); 
         jTIniInscripcio.setText(EOlympicsUtils.getStringDate(prova.getDataIniInscripcio()));    
         jTFiInscripcio.setText(EOlympicsUtils.getStringDate(prova.getDataFiInscripcio())); 
         jLEstat.setText(prova.getEstat());
         jTEsborradaE.setText(""); 
         jTEsborradaF.setText("");
         jTModificadaE.setText(""); 
         jTModificadaF.setText("");
         jTextDataAlta.setText(""); 
         jTextDataBaixa.setText(""); 
         jTextDataModificacio.setText("");
         jTNombrePlaces.setModel(carregarCombo(3,25));
         //jTNombrePlaces.setSelectedIndex(-1);
         
         jTNombrePlaces.setSelectedItem(prova.getNombrePlaces());
         
         
         
         
        
    }   
    private void pintarEtiquetes(){        
    //PROVISIONAL A L'ESPERA DE POSAR ICONES
      
        jBCrearProva.setText("Nova");       
        jBCrearProva.setToolTipText(TDSLanguageUtils.getMessage("proves.pantalla.manteniment.tooltip.crearprova"));                
        jBCancelarProva.setText("Borrar");       
        jBCancelarProva.setToolTipText(TDSLanguageUtils.getMessage("proves.pantalla.manteniment.tooltip.borrarprova"));
        jBCrearProva2.setText("Editar");        
        jBCrearProva2.setToolTipText(TDSLanguageUtils.getMessage("proves.pantalla.manteniment.tooltip.editarprova"));
        jBGuardarProva.setText("Guardar");        
        jBGuardarProva.setToolTipText(TDSLanguageUtils.getMessage("proves.pantalla.manteniment.tooltip.guardarprova"));
        jBBuscarProva.setText("Buscar");        
        jBBuscarProva.setToolTipText(TDSLanguageUtils.getMessage("proves.pantalla.manteniment.tooltip.buscarprova"));
        jBSortir.setText("Sortir");        
        jBSortir.setToolTipText(TDSLanguageUtils.getMessage("proves.pantalla.manteniment.tooltip.sortirprova"));
        
        jLDataAlta.setText(TDSLanguageUtils.getMessage("proves.pantalla.manteniment.settext.jLDataAlta"));
        jLDataBaixa.setText(TDSLanguageUtils.getMessage("proves.pantalla.manteniment.settext.jLDataBaixa"));
        jLDataModificacio.setText(TDSLanguageUtils.getMessage("proves.pantalla.manteniment.settext.jLDataModificacio"));
        jLDescripcio.setText(TDSLanguageUtils.getMessage("proves.pantalla.manteniment.settext.jLDescripcio"));
        jLEsborradaE.setText(TDSLanguageUtils.getMessage("proves.pantalla.manteniment.settext.jLEsborradaE"));
        jLEsborradaF.setText(TDSLanguageUtils.getMessage("proves.pantalla.manteniment.settext.jLEsborradaF"));
        jLEstat.setText(TDSLanguageUtils.getMessage("proves.pantalla.manteniment.settext.jLEstat"));
        jLEstatLabel.setText(TDSLanguageUtils.getMessage("proves.pantalla.manteniment.settext.jLEstatLabel"));
        jLFinsE.setText(TDSLanguageUtils.getMessage("proves.pantalla.manteniment.settext.jLFinsE"));
        jLFinsF.setText(TDSLanguageUtils.getMessage("proves.pantalla.manteniment.settext.jLFinsF"));
        jLInscripcio.setText(TDSLanguageUtils.getMessage("proves.pantalla.manteniment.settext.jLInscripcio"));
        jLInscripcioDe.setText(TDSLanguageUtils.getMessage("proves.pantalla.manteniment.settext.jLInscripcioDe"));
        jLInscripcioFins.setText(TDSLanguageUtils.getMessage("proves.pantalla.manteniment.settext.jLInscripcioFins"));
        jLModificadaE.setText(TDSLanguageUtils.getMessage("proves.pantalla.manteniment.settext.jLModificadaE"));
        jLModificadaF.setText(TDSLanguageUtils.getMessage("proves.pantalla.manteniment.settext.jLModificadaF"));
        jLNPreguntesE.setText(TDSLanguageUtils.getMessage("proves.pantalla.manteniment.settext.jLNPreguntesE"));
        jLNPreguntesF.setText(TDSLanguageUtils.getMessage("proves.pantalla.manteniment.settext.jLNPreguntesF"));
        jLNombrePlaces.setText(TDSLanguageUtils.getMessage("proves.pantalla.manteniment.settext.jLNombrePlaces"));
        jLRealitzacioE.setText(TDSLanguageUtils.getMessage("proves.pantalla.manteniment.settext.jLRealitzacioE"));
        jLRealitzacioF.setText(TDSLanguageUtils.getMessage("proves.pantalla.manteniment.settext.jLRealitzacioF"));
        jLdeE.setText(TDSLanguageUtils.getMessage("proves.pantalla.manteniment.settext.jLdeE"));
        jLdeEF.setText(TDSLanguageUtils.getMessage("proves.pantalla.manteniment.settext.jLdeEF"));        
        jPanelFinal.setBorder(BorderFactory.createTitledBorder(null,TDSLanguageUtils.getMessage("proves.pantalla.manteniment.titoltext.jPanelFinal"),
                                      TitledBorder.DEFAULT_JUSTIFICATION,TitledBorder.DEFAULT_POSITION, fontCapa));         
        jPanelEliminatoria.setBorder(BorderFactory.createTitledBorder(null,TDSLanguageUtils.getMessage("proves.pantalla.manteniment.titoltext.jPanelEliminatoria"),
                                             TitledBorder.DEFAULT_JUSTIFICATION,TitledBorder.DEFAULT_POSITION, fontCapa));                                     
                                      
         
        
    }   
    private DefaultComboBoxModel carregarCombo(Integer min, Integer max){        
        Integer[] n = new Integer[1+(max-min)];
        Integer j=0;
        for(int i=min; i<=max; i++) {n[j]=i; j++;}
        return new DefaultComboBoxModel(n);
    }
    
    public static void main(String args[]) {
        //TDSLanguageUtils.setDefaultLanguage("edu/uoc/tdp/i18n/messages"); 
        
        java.awt.EventQueue.invokeLater(new Runnable() {
            
            public void run() {
                try {
                    new PanelMantenimentGestioProves().setVisible(true);
                    
                } catch (Exception ex) {
                    Logger.getLogger(PanelMantenimentGestioProves.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }
    
    
}
